package builtin

import (
	"talent.com/agency_im/common/msg"
	"talent.com/agency_im/common/user"
	"talent.com/agency_im/conf"
	"talent.com/agency_im/modules/core"
	"talent.com/server/durotar.git/log"
)

type CheckUserStatusInterceptor struct {
}

func (f *CheckUserStatusInterceptor) PreHandle(message *msg.Message) (bool, error) {
	log.Debug("pre handle message on check user status, message: %+v", message)
	if message.SendSelf { // 手动发送消息才检查
		if targetUser, err := user.GetUser(message.TargetID); err != nil {
			return false, err
		} else {
			if targetUser.PlatformID == conf.ServerConfig().Pay.AgencyPlatformID { // 只检查目标用户是代理情况
				if !targetUser.Status {
					log.Debug("send message blocked for agency disable, [%v] - [%v]", message.SourceID, message.TargetID)
					core.SendErrorMsg(message.SourceID, "专员已被禁用，若有疑问请联系在线客服")
					return false, nil
				}
			}
		}
	}
	return true, nil
}

func (f *CheckUserStatusInterceptor) PostHandle(message *msg.Message) error {
	return nil
}
